GBML manual / Text

draw_text_anchored

draw_text, but the position is measured from a spot on the screen (ANCHOR_TOP_LEFT, ANCHOR_BOTTOM_RIGHT, ...) instead of from the top-left corner, and it is fixed to the screen wherever you call it - so a score can say "4 pixels in from the top-left corner" and mean it on any screen.

Works differently on Game Boy Color - Text on the Game Boy Color goes in strips of the screen where you write it, and a strip hides the room behind it. A short text in the middle (up to 8 letters in quotes) is drawn with sprites instead.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

draw_text_anchored(anchor, x, y, text)

Arguments

NameType
anchoranchor
xreal
yreal
textstring

Returns

Nothing.

Description

Draws text fixed to the screen, like draw_text in a Draw GUI event, but you say where by naming a spot on the screen (an anchor) and then how far to move from it. draw_text_anchored(ANCHOR_TOP_LEFT, 4, 4, "SCORE") means "start at the top-left corner, then 4 pixels right and 4 down" - and that stays true on a screen of any size, which a bare pixel number cannot promise (236 is only "4 pixels in from the right edge" on a screen that is 240 wide).

x moves right and y moves down from the anchor, the same directions every position in Gbabel uses. So the offset that keeps text inside the screen points inward: positive from a left or top anchor, negative from a right or bottom one.

In a Draw GUI event, draw_text draws the same text the same way; pick whichever says what you mean. The plain call counts from the top-left pixel of the screen, so ANCHOR_TOP_LEFT is simply the same spot as its (0, 0): draw_text_anchored(ANCHOR_TOP_LEFT, 4, 4, s) and draw_text(4, 4, s) draw on exactly the same pixel. The anchored call is also fixed to the screen wherever you write it (a Step event, a script, any event); the plain one only is inside a Draw GUI event.

Example

draw_text_anchored(ANCHOR_TOP_LEFT, 4, 4, "SCORE 0");
text_align(ALIGN_RIGHT);
draw_text_anchored(ANCHOR_TOP_RIGHT, -4, 4, "LIVES 3");

A score in the top-left corner and the lives in the top-right, each 4 pixels in. The second call sets text_align to right first, so the text ends at its point instead of starting there - that is what keeps it from running off the right edge.

On the GBA

The GBA screen is 240 pixels wide and 160 tall, so ANCHOR_TOP_LEFT is the screen’s top-left pixel, (0, 0), and draw_text_anchored(ANCHOR_TOP_LEFT, 4, 4, s) draws on exactly the same pixel as draw_text(4, 4, s) does inside a Draw GUI event. The call adds the anchor's position to (x, y) and then draws the text fixed to the screen, on the same front-most layer a Draw GUI event uses, so it costs the same as draw_text and follows the same text_align() and font_set() settings. As with every text call, (x, y) is where the middle of the line goes, and one call holds at most 12 letters.

See also: Screen anchorsdraw_texttext_alignANCHOR_TOP_LEFT